package com.taritari.mq.mqconsumber.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author taritari
 * @date 2023-11-29 22:09
 * @description
 */
@Configuration
public class TtlRabbitMqConfiguration {
    //声明交换机注册direct模式的交换机
    @Bean
    public DirectExchange ttlDirectExchange(){
        return new DirectExchange("ttl_direct_exchange",true,false);
    }
    //声明队列 sms.direct.queue email.direct.queue duanxin.direct.queue
    @Bean
    public Queue ttlQueue(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-message-ttl",5000);
        args.put("x-max-length",5);
        args.put("x-dead-letter-exchange","dead_direct_exchange");
        args.put("x-dead-letter-routing-key","dead");
        return new Queue("ttl.direct.queue",true,false,false,args);
    }
    @Bean
    public Queue ttlQueueMessage(){
        return new Queue("ttl.message.direct.queue",true);
    }
    //完成绑定关系
    @Bean
    public Binding ttlBingDing(){
        return BindingBuilder.bind(ttlQueue()).to(ttlDirectExchange()).with("ttl");
    }
    @Bean
    public Binding ttlMessageBingDing(){
        return BindingBuilder.bind(ttlQueueMessage()).to(ttlDirectExchange()).with("ttlMessage");
    }
}
